<?php

namespace App\Http\Controllers\Admin\V1;

use App\Http\Controllers\Controller;
use App\Models\Examination;

class IndexController extends Controller
{
    //后台首页数据
    public function index()
    {
        // 获取进行中的考试数量
        $examIng = Examination::query()
            ->select('id')
            ->groupBy('status')
            ->having('status', 1)
            ->count();

        // 获取已经完成的考试数量
        $examOver = Examination::query()
            ->select('id')
            ->groupBy('status')
            ->having('status', 2)
            ->count();

        // 获取未开始的考试数量
        $noStart = Examination::query()
            ->select('id')
            ->groupBy('status')
            ->having('status', 0)
            ->count();


        // 获取用户信息
        $userInfo = ['username' => auth()->user()->username, 'avatar_url' => ossUrl(auth()->user()->avatar)];
        
        return $this->response->array(['noStart' => $noStart, 'examIng' => $examIng, 'examOver' => $examOver, 'userInfo' => $userInfo]);
    }
}
